from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-14 14:02:17.648670
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 14, Aug, 2022
Time: 14:02:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1341
Nobs: 748.000 HQIC: -50.4756
Log likelihood: 9495.66 FPE: 9.67705e-23
AIC: -50.6897 Det(Omega_mle): 8.58687e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.293959 0.055297 5.316 0.000
L1.Burgenland 0.108397 0.036701 2.954 0.003
L1.Kärnten -0.106770 0.019460 -5.487 0.000
L1.Niederösterreich 0.208602 0.076548 2.725 0.006
L1.Oberösterreich 0.109370 0.074790 1.462 0.144
L1.Salzburg 0.254284 0.039215 6.484 0.000
L1.Steiermark 0.040421 0.051177 0.790 0.430
L1.Tirol 0.107715 0.041533 2.594 0.010
L1.Vorarlberg -0.061703 0.035618 -1.732 0.083
L1.Wien 0.050509 0.066136 0.764 0.445
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061182 0.115489 0.530 0.596
L1.Burgenland -0.033921 0.076649 -0.443 0.658
L1.Kärnten 0.047316 0.040642 1.164 0.244
L1.Niederösterreich -0.175763 0.159870 -1.099 0.272
L1.Oberösterreich 0.407551 0.156200 2.609 0.009
L1.Salzburg 0.287515 0.081901 3.511 0.000
L1.Steiermark 0.107706 0.106883 1.008 0.314
L1.Tirol 0.311859 0.086741 3.595 0.000
L1.Vorarlberg 0.024904 0.074389 0.335 0.738
L1.Wien -0.030674 0.138125 -0.222 0.824
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188371 0.028383 6.637 0.000
L1.Burgenland 0.089738 0.018837 4.764 0.000
L1.Kärnten -0.008672 0.009988 -0.868 0.385
L1.Niederösterreich 0.260299 0.039290 6.625 0.000
L1.Oberösterreich 0.138305 0.038388 3.603 0.000
L1.Salzburg 0.045177 0.020128 2.244 0.025
L1.Steiermark 0.020301 0.026268 0.773 0.440
L1.Tirol 0.093023 0.021318 4.364 0.000
L1.Vorarlberg 0.056827 0.018282 3.108 0.002
L1.Wien 0.117818 0.033946 3.471 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107424 0.028847 3.724 0.000
L1.Burgenland 0.045569 0.019146 2.380 0.017
L1.Kärnten -0.013755 0.010152 -1.355 0.175
L1.Niederösterreich 0.189900 0.039933 4.755 0.000
L1.Oberösterreich 0.301281 0.039016 7.722 0.000
L1.Salzburg 0.109683 0.020457 5.362 0.000
L1.Steiermark 0.103285 0.026698 3.869 0.000
L1.Tirol 0.105517 0.021666 4.870 0.000
L1.Vorarlberg 0.069331 0.018581 3.731 0.000
L1.Wien -0.019059 0.034501 -0.552 0.581
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126490 0.052519 2.408 0.016
L1.Burgenland -0.050120 0.034857 -1.438 0.150
L1.Kärnten -0.040763 0.018482 -2.206 0.027
L1.Niederösterreich 0.172488 0.072702 2.373 0.018
L1.Oberösterreich 0.138352 0.071033 1.948 0.051
L1.Salzburg 0.288949 0.037245 7.758 0.000
L1.Steiermark 0.035403 0.048606 0.728 0.466
L1.Tirol 0.163617 0.039446 4.148 0.000
L1.Vorarlberg 0.099554 0.033829 2.943 0.003
L1.Wien 0.068059 0.062813 1.084 0.279
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056482 0.041760 1.353 0.176
L1.Burgenland 0.039395 0.027716 1.421 0.155
L1.Kärnten 0.051126 0.014696 3.479 0.001
L1.Niederösterreich 0.219616 0.057808 3.799 0.000
L1.Oberösterreich 0.294176 0.056481 5.208 0.000
L1.Salzburg 0.043720 0.029615 1.476 0.140
L1.Steiermark -0.000295 0.038648 -0.008 0.994
L1.Tirol 0.143773 0.031365 4.584 0.000
L1.Vorarlberg 0.071918 0.026899 2.674 0.008
L1.Wien 0.080952 0.049945 1.621 0.105
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174387 0.049880 3.496 0.000
L1.Burgenland -0.002588 0.033105 -0.078 0.938
L1.Kärnten -0.062489 0.017553 -3.560 0.000
L1.Niederösterreich -0.077472 0.069049 -1.122 0.262
L1.Oberösterreich 0.188713 0.067463 2.797 0.005
L1.Salzburg 0.058288 0.035373 1.648 0.099
L1.Steiermark 0.234611 0.046163 5.082 0.000
L1.Tirol 0.498726 0.037464 13.312 0.000
L1.Vorarlberg 0.044881 0.032129 1.397 0.162
L1.Wien -0.054710 0.059657 -0.917 0.359
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160683 0.057665 2.787 0.005
L1.Burgenland -0.008964 0.038272 -0.234 0.815
L1.Kärnten 0.066588 0.020293 3.281 0.001
L1.Niederösterreich 0.206854 0.079825 2.591 0.010
L1.Oberösterreich -0.069952 0.077992 -0.897 0.370
L1.Salzburg 0.210745 0.040894 5.153 0.000
L1.Steiermark 0.120206 0.053368 2.252 0.024
L1.Tirol 0.072608 0.043311 1.676 0.094
L1.Vorarlberg 0.119463 0.037143 3.216 0.001
L1.Wien 0.123187 0.068967 1.786 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358684 0.033064 10.848 0.000
L1.Burgenland 0.007036 0.021944 0.321 0.748
L1.Kärnten -0.023429 0.011635 -2.014 0.044
L1.Niederösterreich 0.214364 0.045770 4.684 0.000
L1.Oberösterreich 0.198920 0.044719 4.448 0.000
L1.Salzburg 0.044280 0.023448 1.888 0.059
L1.Steiermark -0.013652 0.030600 -0.446 0.655
L1.Tirol 0.104247 0.024833 4.198 0.000
L1.Vorarlberg 0.071610 0.021297 3.362 0.001
L1.Wien 0.039862 0.039544 1.008 0.313
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038896 0.139663 0.192142 0.151283 0.118232 0.102846 0.064293 0.216910
Kärnten 0.038896 1.000000 -0.007237 0.132090 0.039267 0.093944 0.432868 -0.053624 0.097237
Niederösterreich 0.139663 -0.007237 1.000000 0.334192 0.141286 0.292565 0.096109 0.180015 0.312839
Oberösterreich 0.192142 0.132090 0.334192 1.000000 0.228308 0.325768 0.176212 0.167465 0.261363
Salzburg 0.151283 0.039267 0.141286 0.228308 1.000000 0.143244 0.112739 0.145312 0.123696
Steiermark 0.118232 0.093944 0.292565 0.325768 0.143244 1.000000 0.146481 0.137656 0.070762
Tirol 0.102846 0.432868 0.096109 0.176212 0.112739 0.146481 1.000000 0.112651 0.142670
Vorarlberg 0.064293 -0.053624 0.180015 0.167465 0.145312 0.137656 0.112651 1.000000 0.002295
Wien 0.216910 0.097237 0.312839 0.261363 0.123696 0.070762 0.142670 0.002295 1.000000